home *** CD-ROM | disk | FTP | other *** search
-
-
- *****Listing 5*****
-
- 001 #include <stdlib.h>
- 002 #include <stdarg.h>
- 003 #include <stdio.h>
- 004 #include "utility.h"
- 005 #ifdef __ZTC__
- 006 #include <fg.h>
- 007 #else
- 008 #include <graph.h>
- 009 #endif
- 010
- 011 int g_white;
- 012 int g_black;
- 013
- 014 void fatal(char *s)
- 015 {
- 016 printf("FATAL ERROR: %s\n", s);
- 017 exit(1);
- 018 }
- 019
- 020 void trace(char *fmt, ...)
- 021 {
- 022 static FILE *outfp = NULL;
- 023 va_list arg_ptr;
- 024 va_start(arg_ptr, fmt);
- 025 if (outfp == NULL) {
- 026 unlink("tf");
- 027 if ((outfp = fopen("tf", "w")) == NULL)
- 028 fatal("fopen failed\n");
- 029 setbuf(outfp, NULL);
- 030 }
- 031 vfprintf(outfp, fmt, arg_ptr);
- 032 va_end(arg_ptr);
- 033 }
- 034
- 035 /* utility function to put screen in graphics mode */
- 036 void g_init(void)
- 037 {
- 038 #ifdef __ZTC__
- 039 fg_init_all();
- 040 g_white = FG_WHITE;
- 041 g_black = FG_BLACK;
- 042 #else
- 043 struct videoconfig this_screen;
- 044 _getvideoconfig(&this_screen);
- 045 switch (this_screen.adapter)
- 046 {
- 047 case _CGA:
- 048 case _OCGA:
- 049 _setvideomode(_HRESBW);
- 050 break;
- 051 case _EGA:
- 052 case _OEGA:
- 053 _setvideomode(_ERESCOLOR);
- 054 break;
- 055 case _VGA:
- 056 case _OVGA:
- 057 case _MCGA:
- 058 _setvideomode(_VRES2COLOR);
- 059 break;
- 060 case _HGC:
- 061 _setvideomode(_HERCMONO);
- 062 break;
- 063 default:
- 064 printf("This program requires a CGA, EGA, MCGA,");
- 065 printf("VGA, or Hercules card\n");
- 066 exit(0);
- 067 }
- 068 g_white = _getcolor();
- 069 g_black = 0;
- 070 #endif
- 071 }
- 072
- 073 /* utility function - wait for a key so we can see
- 074 graphics, set video mode back to character mode */
- 075 void cleanup()
- 076 {
- 077 int ch;
- 078 ch = getchar();
- 079 #ifdef __ZTC__
- 080 fg_term();
- 081 #else
- 082 _setvideomode(_DEFAULTMODE);
- 083 #endif
- 084 /*lint -esym(550,ch) */
- 085 }
- 086 /*lint +esym(550,ch) */
- 087
- 088 void g_circle(int y, int x, int radius, int color)
- 089 {
- 090 #ifdef __ZTC__
- 091 fg_drawarc((fg_color_t)color, FG_MODE_SET, ~0, x, y,
- 092 radius, 0, 3600, fg_displaybox);
- 093 #else
- 094 _setcolor(color);
- 095 _ellipse(_GBORDER, x - radius, y - radius, x + radius,
- 096 y + radius);
- 097 #endif
- 098 }
- 099
- 100 void g_square(int y, int x, int size, int color)
- 101 {
- 102 #ifdef __ZTC__
- 103 int hs;
- 104 fg_box_t box;
- 105 hs = size / 2;
- 106 box[FG_X1] = x - hs;
- 107 box[FG_Y1] = y - hs;
- 108 box[FG_X2] = x + hs;
- 109 box[FG_Y2] = y + hs;
- 110 fg_drawbox((fg_color_t)color, FG_MODE_SET, ~0,
- 111 FG_LINE_SOLID, box, fg_displaybox);
- 112 #else
- 113 int hs;
- 114 hs = size / 2;
- 115 _setcolor(color);
- 116 _rectangle(_GBORDER, x - hs, y - hs, x + hs, y + hs);
- 117 #endif
- 118 }
-